package com.heima.wemedia.controller;

import com.heima.common.enums.AppHttpCodeEnum;
import com.heima.common.exception.LeadException;
import com.heima.common.util.BeanHelper;
import com.heima.model.media.dtos.WmUserDto;
import com.heima.wemedia.entity.WmUser;
import com.heima.wemedia.service.WmUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 自媒体用户相关
 */
@RestController
@RequestMapping("/api/v1/wmuser")
public class WemediaController {

    @Autowired
    private WmUserService wmUserService;

    /**
     * 新增自媒体账号
     * 返回自媒体账号的id
     */
    @PostMapping("/save")
    public Integer save(@RequestBody WmUserDto wmUserDto){
        return wmUserService.saveWmUser(wmUserDto);
    }

    /**
     * 通过用户id查询自媒体账号
     */
    @GetMapping("/findByApUserId/{id}")
    public WmUserDto findByApUserId(@PathVariable("id") Integer id){
        WmUserDto wmUser = wmUserService.findByApUserId(id);
        if (wmUser==null){
            throw new LeadException(AppHttpCodeEnum.DATA_NOT_EXIST);
        }
        return wmUser;
    }



}
